namespace KinonekoSoftware.CodariaDB.Documents.Templates
{
    public sealed class InstanceTemplate : RootObject
    {
        private bool         _useCustomType;
        private string       _customType;
        private InstanceType _builtinType;

        /// <summary>
        /// 获取或设置 <see cref="BuiltinType"/> 属性。
        /// </summary>
        public InstanceType BuiltinType
        {
            get => _builtinType;
            set
            {
                SetValue(ref _builtinType, value);
                RaiseUpdated(nameof(Name));
            }
        }

        /// <summary>
        /// 获取或设置 <see cref="CustomType"/> 属性。
        /// </summary>
        public string CustomType
        {
            get => _customType;
            set
            {
                SetValue(ref _customType, value);
                RaiseUpdated(nameof(Name));
            }
        }

        /// <summary>
        /// 获取或设置 <see cref="UseCustomType"/> 属性。
        /// </summary>
        public bool UseCustomType
        {
            get => _useCustomType;
            set
            {
                SetValue(ref _useCustomType, value);
                RaiseUpdated(nameof(Name));
            }
        }

        [Runtime]
        [BsonIgnore]
        public string Name
        {
            get
            {
                if (UseCustomType)
                {
                    return CustomType;
                }

                return LanguageManager.GetEnum(BuiltinType);
            }
        }

        public required ObservableCollection<CompositeItem>      Properties  { get; init; }
        public required ObservableCollection<DataPartDefinition> Definitions { get; init; }
    }
}